package com.hgcode.platform.service.impl;

import com.hgcode.platform.entity.User;
import com.hgcode.platform.repository.UserMapper;
import com.hgcode.platform.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Long save(User user) {
        int id= userMapper.insert(user);
        userMapper.selectById(user.getId());
        return user.getId();
    }

    @Override
    public void transactionDemo() {
        User user=userMapper.selectById(1040626231556882433L);
        user.setName("谢桂英");
        userMapper.update(user,null);
        int s=1/0;
        update();
    }

    @Override
    @Transactional
    public void find() {
        User user=userMapper.selectById(1040626231556882433L);
        System.out.println(user);
    }

    private void update(){
        User user=new User();
        user.setAge(2);
        user.setName("xiaoxie");
        userMapper.insert(user);
    }
}
